package com.klarna.raas.ws.services;

import java.math.BigInteger;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.klarna.raas.ws.dao.IPersonDao;
import com.klarna.raas.ws.domain.PersonInfo;

/**
 * The Class FundService.
 */
@Service
public class LookupService {

	private static final Logger logger = Logger.getLogger(LookupService.class);
	@Autowired
	private IPersonDao dao;
	/**
	 * Get the fund by id.
	 *
	 * @param fundId_p
	 *            the fund id_p
	 * @return the fund by id
	 */
	public PersonInfo getPersonInfoById(String id) {
		logger.info("getPersonInfoById START");
		
		PersonInfo person = new PersonInfo();
		
		person.setId(new BigInteger(id));
		String firstName = null;
		person.setFirstName(firstName);
		String lastName = null;
		person.setLastName(lastName);
		String street = null;
		person.setStreet(street);
		String city = null;
		person.setCity(city);
		String zip = null;
		person.setZip(zip);
		String careOf = null;
		person.setCareOf(careOf);
		String country = null;
		person.setCountry(country);
		String birthDate = null;
		person.setBirthDate(birthDate);
		
		List<PersonInfo> pList = dao.select(id);
		if (pList != null && !pList.isEmpty()) {
			person = pList.get(0);
		}
		logger.info("result=" + person);
		logger.info("getPersonInfoById END");

		return person;
	}
	
	public PersonInfo getPersonInfoByMultipleParams(String birthDate,
			String firstName, String lastName, String street, String zip) {
		logger.info("getPersonInfoByMultipleParams START");
		String paramsMessage = "Params recieved[" +
				"birthDate=" + birthDate
				+ ",firstName=" + firstName
				+ ",lastName=" + lastName
				+ ",street=" + street
				+ ",zip=" + zip
				+ "]";
		
		logger.info(paramsMessage);

		PersonInfo person = new PersonInfo();

		List<PersonInfo> pList = dao.selectMultipleParams(birthDate, firstName, lastName, street, zip);
		person = null;
		if (pList != null && !pList.isEmpty()) {
			person = pList.get(0);
		}
		logger.info("result=" + person);
		logger.info("getPersonInfoByMultipleParams END");

		return person;
	}
	
	public IPersonDao getDao() {
		return dao;
	}
	public void setDao(IPersonDao dao) {
		this.dao = dao;
	}




}
